package com.xbongbong.pro.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 直辖市枚举
 * @author xinpeng.jiang
 * @date 2021/3/5 23:45
 * @version 1.0
 * @since V1.0
 */
@Getter
public enum MunicipalityEnum {
    /**
     * 直辖市，目前4个
     */
    BEI_JING(1, "enum.municipality.Name.beijing"),

    TIAN_JING(2, "enum.municipality.Name.tianjing"),

    CHONG_QING(3, "enum.municipality.Name.chongqing"),

    SHANG_HAI(4, "enum.municipality.Name.shanghai"),

    ;


    private final Integer code;

    private final String name;


    MunicipalityEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public static MunicipalityEnum getByCode(Integer code) {
        for (MunicipalityEnum cacheCode : values()) {
            if (Objects.equals(code, cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return null;
    }

    public static boolean isExist(String name) {
        for (MunicipalityEnum cacheCode : values()) {
            if (Objects.equals(name, I18nMessageUtil.getMessage(cacheCode.getName()))) {
                return true;
            }
        }
        return false;
    }
}
